import { globalShortcut } from "electron";

const initGlobalShortcut = (win) => {
  if (process.platform === "darwin") {
    let contents = win.webContents;
    globalShortcut.register("CommandOrControl+C", () => {
      contents.copy();
    });
    globalShortcut.register("CommandOrControl+V", () => {
      contents.paste();
    });
    globalShortcut.register("CommandOrControl+X", () => {
      contents.cut();
    });
  }
};
// 快捷键与窗口绑定
export const bindGlobalShortcut = (win) => {
  // const win = BrowserWindow.getFocusedWindow();
  win.on("focus", () => {
    // 注册全局快捷键
    initGlobalShortcut(win);
  });

  win.on("blur", () => {
    // 失去焦点，注销快捷键
    globalShortcut.unregisterAll();
  });
};